package com.yj.controller;

import com.yj.AppHttpCodeEnum;
import com.yj.AppUserService;
import com.yj.Result.ResponseResult;
import com.yj.apUser.pojo.ApUser;
import com.yj.service.ApUserService;
import com.yj.service.impl.ApUserServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.Map;

@Slf4j
@RestController
@RequestMapping("/app/user")
public class AppUserController {
    @Autowired
    private ApUserService apUserService;
    /**
     * 实现 用户端手机号验证码接受
     * 参数 user httpSession 接收验证码
     */
    @PostMapping("/sendMsg")
    public ResponseResult sendMsg(@RequestBody ApUser tuser, HttpSession httpSession) throws Exception {
        System.out.println(tuser);
        return apUserService.sendMsg(tuser,httpSession);
    }

    /**
     * 实现 用户端手机号验证码登录功能
     * 参数 LoginDto 手机号 phone 接收验证码
     */
    @PostMapping("/login")
    public ResponseResult login(@RequestBody ApUser user, HttpSession httpSession) throws Exception {
        System.out.println(user);
        return  apUserService.loginByPhone(user,httpSession);
    }


    /**
     * app用户注册
     * @param map app端用户信息
     * @return ResponseResult
     */
    @PostMapping("/register")
    public ResponseResult register(@RequestBody Map<String,Object> map){
        try {
            return apUserService.register(map);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseResult.errorResult(AppHttpCodeEnum.REGISTER_ERROR);
    }



}
